//
//  UIAlertController+Extension.swift
//  GermanyMedical
//
//  Created by 刘培壮 on 16/9/8.
//  Copyright © 2016年 上海实奥信息科技有限公司. All rights reserved.
//

import UIKit

extension UIAlertController {
    
    class func showAlert(
        _ presentController: UIViewController!,
        title: String!,
        message: String!,
        cancelButtonTitle: String? = "cancel",
        okButtonTitle: String? = "ok") {
        let alert = UIAlertController(title: title!, message: message!, preferredStyle: .alert)
        if (cancelButtonTitle != nil) {
            alert.addAction(UIAlertAction(title: cancelButtonTitle!, style: .default, handler: nil))// do not handle cancel, just dismiss
        }
        if (okButtonTitle != nil) {
            alert.addAction(UIAlertAction(title: okButtonTitle!, style: .default, handler: nil))// do not handle cancel, just dismiss
        }
        
        presentController!.present(alert, animated: true, completion: nil)
    }
    
    class func showAlert(
        _ presentController: UIViewController!,
        title: String!,
        message: String!,
        cancelButtonTitle: String? = "cancel",
        okButtonTitle: String? = "ok",
        okHandler: ((UIAlertAction?) -> Void)!) {
        let alert = UIAlertController(title: title!, message: message!, preferredStyle: .alert)
        if (cancelButtonTitle != nil) {
            alert.addAction(UIAlertAction(title: cancelButtonTitle!, style: .default, handler: nil))// do not handle cancel, just dismiss
        }
        if (okButtonTitle != nil) {
            alert.addAction(UIAlertAction(title: okButtonTitle!, style: .default, handler: okHandler))// do not handle cancel, just dismiss
        }
        
        presentController!.present(alert, animated: true, completion: nil)
    }
}
